<template>
  <div style="height:100%" v-loading="loading">
    <v-tableTitle
        :btnConfig="btnConfig"
        :title="$t('outbound.skuType')"
        @newCreate="newCreate"
        @copy="copy"
        @del="del"
    ></v-tableTitle>
    <ag-grid
        class="base-grid"
        :hasCheck="true"
        :hasIndex="false"
        :hasEdit="true"
        v-model="gridObj"
        :defaultColDef="defaultColDef"
        :highlightCurrentRow="false"
        :disabled="true"
        :data="rowData"
        :rules="rules"
        :height="height"
        :tmsShowFilter="true"
        :columnConfig="columnConfig"
        :extraColumns="extraColumns"
        :showSummary="false"
        :pagination="true"
        :tableSettingVisible.sync="showTableSetting"
        :page="page"
        :pageSize="pageSize"
        :total="total"
        @selection-change="handleSelectionChange"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @setdialog="setdialog"
        @filter-changed="filterChanged"
        @cell-dblclick="cellDblclick"
        @grid-ready="agGridReady"
    >
    </ag-grid>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import agGridBaseMixin from "@/mixins/AgGridBaseMixin";
import { querySkuTypeGroupByPage, querySkuTypeGroupById, insertSkuTypeGroup, updateSkuTypeGroup, batchDeleteSkuTypeGroupByIds }from "@/api/skuTypeGroup/skuTypeGroup";
export default {
  name: "skuTypeGroup",
  mixins: [baseMixin, agGridBaseMixin],
  data() {
    return {
      height: 0,
      columnConfig:{ menu_id: 993, menu_code:"skuTypeGroup", menu_list_code:"skuTypeGroup", },
      defaultColDef: {}
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('common.create'), certigier: this.newStatus||!this.btnPermNameList.includes('EN021001'), invalid: "newCreate" },
        { label: this.$t('common.copy'), certigier: this.copyStatus||!this.btnPermNameList.includes('EN021002'), invalid: "copy" },
        { label: this.$t('common.delete'), certigier: this.delStatus||!this.btnPermNameList.includes('EN021003'), invalid: "del" }
      ];
    }
  },
  mounted() {
    this.height = this.getHeight(window);
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", "");
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, 20);
  },
  methods: {
    newCreate() {
      this.$store.commit("setNewFlag", true);
      this.$router .push({name: "skuTypeGroupDrawer"});
    },
    copy() {
      let selectedList = this.gridObj.getSelectedRows();
      if (selectedList.length !== 1 || selectedList === null || selectedList === undefined) {
        this.$message.error(this.$t('msg.msg11'));
        return;
      }

      this.$store.commit("setNewFlag", true);
      // 子页面传值
      let query = {copy: true, obj:selectedList[0]};
      this.$router .push({name: "skuTypeGroupDrawer", query: query});
    },
    del() {
      let selectedList = this.gridObj.getSelectedRows();
      if (selectedList.length === 0 || selectedList === null || selectedList === undefined) {
        this.$message.error(this.$t('msg.msg12'));
        return;
      }
      let data = [];
      selectedList.forEach(item => {
        data.push(item.id);
      });
      batchDeleteSkuTypeGroupByIds(data).then(res => {
          this.$message.success(this.$t('app.delMes'));
          this.getTableData(1, 20);
      });
    },
    agGridReady(params) {
      this.gridObj = params.api;
    },
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({name: "skuTypeGroupDrawer"});
    },
    getTableData(page, pageSize) {

      let data = { pageNum: page, pageSize: pageSize };
      querySkuTypeGroupByPage(data).then(res => {
          this.rowData = res.data.list;
          // 转义
          this.rowData.forEach((item, index) => {
            if (item.importType === 10301) {
              item.importType = this.$t('bill.orderNo');
            } else if (item.importType === 10302) {
              item.importType = this.$t('home1.asn');
            }
          });
          this.page = res.pageNum;
          this.pageSize = res.pageSize;
          this.total = res.data.total;
      });
    }
  }
};
</script>

<style></style>